package com.maijinjie.admin.content.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.maijinjie.common.bean.Pagination;
import com.maijinjie.common.bean.StatusBean;
import com.maijinjie.admin.content.bean.PictureItemBean;
import com.maijinjie.admin.content.dao.PictureItemMapper;
import com.maijinjie.admin.content.field.PictureItemFields;
import com.maijinjie.admin.content.service.PictureItemService;
import com.maijinjie.common.service.impl.BaseServiceImpl;

/**
 * PictureItemServiceImpl
 * @author 罗正杰
 **/
@Service("pictureItemService")
public class PictureItemServiceImpl extends BaseServiceImpl implements PictureItemService{
	@Resource
	PictureItemMapper pictureItemMapper;
	
	@Override
	public PictureItemBean getBeanById(Integer id) throws Exception{
		if(null==id || 0>=id){
			return null;
		} else {
			return (PictureItemBean) getBeanById(pictureItemMapper, id);
		}
	}
	@Override
	public int count(Map<String, Object> params) throws Exception {
		return pictureItemMapper.count(params);
	}
	@Override
	public List<PictureItemBean> list(Map<String, Object> params) throws Exception {
		return (List<PictureItemBean>) pictureItemMapper.list(params);
	}
	@Override
	public StatusBean save(PictureItemBean bean, String createBy, Integer createUserId) throws Exception {
		Date currDate = new Date();
		//TODO 处理业务
		
		if(0<pictureItemMapper.save(bean)){
			return success("操作成功！");
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean update(PictureItemBean bean, String createBy, Integer createUserId) throws Exception {
		if(null!=bean){
			Date currDate = new Date();
			HashMap<String, Object> params = new HashMap<String, Object>();
			//TODO 处理业务
			
			if(pictureItemMapper.update(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean deleteById(Integer id) throws Exception {
		if(null!=id && 0<id){
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(PictureItemFields.id.toString(), id);
			if(pictureItemMapper.delete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public Pagination<PictureItemBean> list(Pagination<PictureItemBean> pagination) throws Exception {
		return (Pagination<PictureItemBean>) getPagination(pictureItemMapper, pagination);
	}
	@Override
	public StatusBean batchDelete(String ids) throws Exception {
		if(null!=ids && !"".equals(ids.trim())) {
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(PictureItemFields.id.toString(), ids);
			if(pictureItemMapper.batchDelete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public List<PictureItemBean> listAll() throws Exception {
		return (List<PictureItemBean>) pictureItemMapper.list(null);
	}
}
